import defaultImage from "../assets/notfound.png";

export function setDefaultImage(e) {
  e.target.src = defaultImage
  e.target.title = "图片加载失败"
}
export function formatDate(dateString) {
  const daysOfWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];

  const date = new Date(dateString);
  const today = new Date();

  // 设置时间为整天（去除时间部分的影响）
  today.setHours(0, 0, 0, 0);

  const pastSunday = new Date(today);
  pastSunday.setDate(today.getDate() - today.getDay());

  const nextSunday = new Date(today);
  nextSunday.setDate(today.getDate() + (6 - today.getDay()));

  // 格式化日期为 YYYY-MM-DD
  const formattedDate = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;

  if (date >= pastSunday && date <= nextSunday) {
    // 如果在本周内，则返回星期几
    return daysOfWeek[date.getDay()];
  } else {
    // 否则返回格式化的日期
    return formattedDate;
  }
}
